package org.UserHouse.Servlet;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.UserHouse.Dao.HitemDao;
import org.UserHouse.Dao.Imp.HitemDaoImp;
import org.UserHouse.Dao.Imp.TypeDaoImp;
import org.UserHouse.Dao.TypeDao;
import org.UserHouse.entity.Hitem;
import org.UserHouse.entity.Type;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @author bin
 * @date 2024-12-16
 */
@WebServlet("/list.type.do")
public class listTypeServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
        PrintWriter out = resp.getWriter();

        TypeDao typeDao = new TypeDaoImp();
        List<Type> list = typeDao.SelectType();

        String json = gson.toJson(list);
        out.println(json);

        out.flush();
        out.close();
    }
}
